#include "LinkStack.h"

template<typename T>
LinkStack<T>::LinkStack(void)
{
	top=NULL;
}

template<typename T>
LinkStack<T>::~LinkStack(void)
{
	Node<T> *p = top;
	while (NULL != p)
	{
		top = p->next;
		delete p;
		p=top;
	}
}

template<typename T>
void LinkStack<T>::Push(T value)
{
	Node<T> *p = new Node<T>;
	p->data = value;
	p->next = top;
	top = p;
}

template<typename T>
T LinkStack<T>::Pop()
{
	if (NULL == top)
	{
		cout<<"underflow"<<endl;
		return -1;
	}
	Node<T> *p = top->next;
	T retValue = top->data;
	delete top;
	top=p;
	return retValue;
}
template<typename T>
bool LinkStack<T>::IsEmpty()
{
	return top==NULL? true: false;
}

template<typename T>
void LinkStack<T>::PrintStack()
{
	Node<T> *p = top;
	while (NULL != p)
	{
		cout<<p->data<<"   ";
		p=p->next;
	}
}
